#ifndef WIN_COMPEDIT
#define WIN_COMPEDIT
#include "controls.h"
#include "editctrls.h"
#include <string>
#include <vector>

namespace win
{
    using std::string;
    
	class CompositeEditBox : public ChildWindow
	{
    	static
        	LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,
						  WPARAM wParam, LPARAM lParam);
	    public:
            class Item
            {  
                public:
                    Item(const string& label, TextControl * pCtl, const string& hint);
                    const string& Label() const
                        { return _label; }
                    TextControl * Ctl() const
                        { return _pCtl; }    
                    ~Item();
                private:
                    string _label, _hint;
                    TextControl * _pCtl;
                    
            };    
            typedef std::vector<Item*> ItemPtrBasket;
                    
		public:
            CompositeEditBox();
            // set the font before adding the controls
            void SetControlFont(HFONT font);
			void Create(Window &parent,const int child_index);
			// once items are given to the control, the
			// items belongs to the control
			void SetItems(const ItemPtrBasket &);
			// removes all items. if redraw - window is repainted
			void ClearItems(bool redraw=true);
			bool HasItems();
        	const ItemPtrBasket & Items()
        		{ return _items; }
		private:
			void AdjustItemDimensions();
		    int IndexOf(HWND handle);   
			void OnSize(const int w, const int h);
			void AdjustControlLayout();
			void OnPaint();
			void OnScroll(int n);
			void OnScrollPos(const int p);
			void OnScrollPage(const int n);
			void OnFocus(HWND handle);
		    ItemPtrBasket _items;
            int _itemHeight;        // display height of an item
            int _displayHeight;     // number of items in display
            int _itemWidth;         // display widh of an item
            int _ySize;             // number of lines per page
            int _yPos;              // current line on top of display
            HFONT _controlFont;

	};
}	
#endif
